package com.dlc.beijingrfid.activity;

import android.content.Intent;
import android.os.Bundle;
import android.text.TextUtils;
import android.util.Log;
import android.view.View;
import android.widget.EditText;
import android.widget.Toast;
import butterknife.BindView;
import com.dlc.commonlibrary.dialog.WaitingDialog;
import com.dlc.commonlibrary.utils.ToastUtil;
import com.dlc.commonlibrary.widget.TitleBar;
import com.dlc.beijingrfid.R;
import com.dlc.beijingrfid.base.BaseActivity;
import com.dlc.beijingrfid.net.bean.LoginBean;
import com.dlc.beijingrfid.net.exception.ErrorMsgException;
import com.dlc.beijingrfid.net.protocol.UserProto;
import com.dlc.beijingrfid.net.protocol.base.HttpProtocol;
import com.lzy.okgo.model.HttpParams;

/**
 * Created by Administrator on 2017/7/18 0018.
 */

public class ChangeNicknameActivity extends BaseActivity {
    @BindView(R.id.titleBar)
    TitleBar titleBar;
    @BindView(R.id.nickname_et)
    EditText nickname_et;
    private WaitingDialog mDialog;
    String nickname;
    @Override
    protected int getLayoutID() {
        return R.layout.activity_change_nickname;
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        titleBar.leftExit(this);
    }
    public void alter(View view){
        final String nicknameStr=nickname_et.getText().toString();
        if(TextUtils.isEmpty(nicknameStr)){
            Toast.makeText(this,"昵称不能为空",Toast.LENGTH_SHORT).show();
            return;
        }
        showLoadingDialog();
        HttpParams params=new HttpParams();
        params.put("nickname",nicknameStr);
        UserProto.get().alterUserMsg(params, new HttpProtocol.Callback<LoginBean>() {
            @Override
            public void onSuccess(LoginBean loginBean) {
                dismissLoadingDialog();
                ToastUtil.show(ChangeNicknameActivity.this,loginBean.msg);
                Intent intent=new Intent();
                intent.putExtra("nickname",nicknameStr);
                setResult(2,intent);
                finish();
            }
            @Override
            public void onFailed(int code, ErrorMsgException e) {
                dismissLoadingDialog();
                Log.d("昵称修改失败的信息--->",code+e.getMessage());
                ToastUtil.show(ChangeNicknameActivity.this,e.getMessage());
            }
        });
    }

}
